%%html
<style>
.output_wrapper, .output {
height:auto !important;
max-height:1000px; /* your desired max-height here */
}
.output_scroll {
box-shadow:none !important;
webkit-box-shadow:none !important;
}
.container {
width:100% !important;
height:100% !important;
}
</style>
import numpy as np
from plotly.offline import init_notebook_mode, iplot
import matplotlib.pyplot as plt
init_notebook_mode(connected=True)
# pull data from csvs and create numpy arrays for each field
csv = np.genfromtxt ('C:/Users/bobby/Documents/bpHeatMapTest2.csv', delimiter=",")
csv2 = np.genfromtxt ('C:/Users/bobby/Documents/bpHeatMapTest2.csv', delimiter=",", dtype=str)
noHeader = csv[1:-1,:]
noHeader2 = csv2[1:-1,:]
stoloc = noHeader[:,0]
xs = noHeader[:,1]
ys = noHeader[:,2]
zs = noHeader[:,3]
arecod = noHeader[:,4]
# 2d array for pick data
picks = []
for i in range(5,noHeader.shape[1]):
picks.append(noHeader[:,i])
# create initial data record
data=[dict(name='1',
type='scatter3d',
x=xs, y=ys, z=zs,
text=stoloc,
mode='markers',
marker=dict(
size=6,
symbol='square',
color=picks[0],
colorscale='Reds',
opacity=0.4,
line=dict(
width=0,
color='white')
)
)
]
# define initial camera angles
camera = dict(
up=dict(x=0, y=0, z=1),
center=dict(x=0, y=0, z=0),
eye=dict(x=6, y=-6, z=2.5)
)
# define layout
layout=dict(margin=dict(l=10,r=10,b=0,t=50),
height=750,
width=1500,
scene=dict(aspectratio=dict(x=10,y=10, z=1), camera=camera),
paper_bgcolor='rgb(111, 152, 198)',
title='BP Picks', hovermode='closest',
updatemenus = [dict(type='buttons',
buttons=[dict(label='Play',
method='animate',
args=[None, dict(frame=dict(duration=500,
redraw=False),
fromcurrent=True,
transition=dict(duration=300,
easing='cubic-in-out'))])])])
frames=[]
# define slider dictionry properties
sliders_dict = dict(active=0,
yanchor='bottom',
xanchor='left',
currentvalue=dict(font=dict(size=15),
prefix='Week:',
visible=True,
xanchor='right'),
transition=dict(duration=300,
easing='cubic-in-out'),
pad=dict(b=5, t=5),
len=0.5,
x=0.1,
y=0,
steps=[])
# loop through each week's pick data and create a frame and slider record each time
for i in range(1, len(picks)+1):
frame = dict(name=str(i),
data=[dict(name=str(i),
type='scatter3d',
x=xs, y=ys, z=zs,
text=stoloc,
mode='markers',
marker=dict(size=6,
symbol='square',
color=picks[i-1],
colorscale='Reds',
opacity=0.4,
line=dict(width=0,
color='white'
)
)
)
]
)
frames.append(frame)
slider_step=dict(args=[[i],
dict(frame=dict(duration=300,
redraw=False),
mode='immediate',
transition=dict(duration=300))],
label=i,
method='animate')
sliders_dict['steps'].append(slider_step)
# add slider records to layout
layout['sliders'] = [sliders_dict]
# create figure
figure1=dict(data=data, layout=layout, frames=frames)
# show figure
iplot(figure1)
# pull data from csvs and create numpy arrays for each field
csv = np.genfromtxt ('C:/Users/bobby/Documents/bpConfig.csv', delimiter=",")
csv2 = np.genfromtxt ('C:/Users/bobby/Documents/bpConfig.csv', delimiter=",", dtype=str)
noHeader = csv[1:-1,:]
noHeader2 = csv2[1:-1,:]
stoloc = noHeader[:,0]
xs = noHeader[:,1]
ys = noHeader[:,2]
zs = noHeader[:,3]
arecod = noHeader2[:,5]
trvseq = noHeader[:,6]
wrkzon = noHeader2[:,7]
locacc = noHeader2[:,8]
data=[]
# define initial camera angles
camera = dict(
up=dict(x=0, y=0, z=0),
center=dict(x=0, y=0, z=0),
eye=dict(x=6, y=-6, z=2.5)
)
# define layout
layout=dict(margin=dict(l=10,r=10,b=0,t=50),
height=750,
width=1500,
scene=dict(aspectratio=dict(x=10,y=10, z=1), camera=camera),
paper_bgcolor='rgb(127, 127, 127)',
title='BP Areas', hovermode='closest',
updatemenus = [dict(type='buttons',
buttons=[dict(label='Play',
method='animate',
args=[None])]),
dict(x=-0.05,
y=1,
buttons=[dict()])])
# create lists of traces and their headers
traces = [arecod, trvseq, wrkzon, locacc]
traceLabels = ['Areas', 'Travel Sequence', 'Work Zones', 'Location Access']
# loop through each trace, configure it, and add to data
for i, trace in enumerate(traces):
# establishes the first trace as the only one shown on start
if i == 0:
vis=True
else:
vis=False
# create trace template
tempTrace = dict(
type='scatter3d',
showlegend=False,
visible=vis,
name=traceLabels[i],
x=xs, y=ys, z=zs,
text=trace,
mode='markers',
marker=dict(
size=6,
symbol='square',
line=dict(
width=0.5,
color='white'
)
)
)
# determine whether discrete or continuous and define color assignments
if trace.dtype.type is np.str_:
cmap = plt.get_cmap('jet')
values = np.unique(trace)
colors = cmap(np.linspace(0, 1, len(values)))
valueColor = dict()
colorArray = []
for j, value in enumerate(values):
valueColor[value]=colors[j]
for location in trace:
colorArray.append(valueColor[location])
tempTrace['marker']['color'] = colorArray
else:
tempTrace['marker']['color'] = trace
tempTrace['marker']['colorscale'] = 'Reds'
tempTrace['marker']['colorbar'] = dict(thickness = 30)
data.append(tempTrace)
# create dropdown
visible = []
for j in range(0,5):
if j == i:
visible.append(True)
else:
visible.append(False)
updatemenu = dict(
args=['visible', visible],
label=traceLabels[i],
method='restyle'
)
layout['updatemenus'][1]['buttons'].append(updatemenu)
# create figure
figure=dict(data=data, layout=layout)
# show figure
iplot(figure)